//
// util.cc
// (c) Yongjin Park, Apr 17, 2012
//

#include "util.hh"

////////////////////////////////////////////////////////////////
std::string curr_time()
{
  time_t rawtime;
  time ( &rawtime );
  struct tm * timeinfo = localtime ( &rawtime );
  char buff [80];
  strftime (buff,80,"%c",timeinfo);
  return std::string(buff);
}

////////////////////////////////////////////////////////////////
// log sum (from Blei's LDA code)
// return log( a+b ) given log(a) and log(b)
double log_sum(double log_a, double log_b)
{
  double v;

  if (log_a < log_b)
    {
      v = log_b+log(1 + exp(log_a-log_b));
    }
  else
    {
      v = log_a+log(1 + exp(log_b-log_a));
    }
  return(v);
}

//EOF
